package cn.fresh.xuanyuan.module.member.dal.mysql.user;

import cn.fresh.xuanyuan.framework.mybatis.core.mapper.BaseMapperX;
import cn.fresh.xuanyuan.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.fresh.xuanyuan.module.member.dal.dataobject.user.MemberLikeDO;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface MemberLikeMapper extends BaseMapperX<MemberLikeDO> {

    default MemberLikeDO isExist(Long userId, Long spuId) {
        LambdaQueryWrapperX<MemberLikeDO> queryWrapperX = new LambdaQueryWrapperX<>();
        queryWrapperX.eq(MemberLikeDO::getUserId, userId).eq(MemberLikeDO::getSpuId, spuId).eq(MemberLikeDO::getDeleted, false);
        MemberLikeDO likeDO = selectOne(queryWrapperX);
        return likeDO;
    }

    default void remove(Long userId, Long spuId) {
        LambdaQueryWrapperX<MemberLikeDO> queryWrapperX = new LambdaQueryWrapperX<>();
        queryWrapperX.eq(MemberLikeDO::getUserId, userId).eq(MemberLikeDO::getSpuId, spuId);
        delete(queryWrapperX);
    }
}
